
var StockSpanner = function() {

};

/** 
 * @param {number} price
 * @return {number}
 */
StockSpanner.prototype.next = function(price) {

};

/**
 * Your StockSpanner object will be instantiated and called as such:
 * var obj = new StockSpanner()
 * var param_1 = obj.next(price)
 */
const test = function(a) {
    const stack = []
    let ans = new Array(a.length).fill(1)
    for(let i = 0; i < a.length; i++) {
        while(stack.length !== 0 && stack[stack.length - 1][0] <= a[i]) {
            stack.pop()
        }
        if(stack.length === 0) ans[i] = i + 1
        else {
            ans[i] = i - stack[stack.length - 1][1]
        }
        stack.push([a[i], i])
    }
    return ans
}
console.log(test([100,80,60,70,60,75,85]));
console.log(test([1,2,1,3,1]));